using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using ProgramMain.RecurringTariffPlans;
using ProgramMain.Framework;

namespace ProgramMain.UniversalTariffPlans
{
    public partial class UniversalTariffEditorCtl : BaseDetailCtl
    {
        public UniversalTariffEditorCtl()
        {
            InitializeComponent();
        }

        public UniversalTariffListCtl.ServiceCategoryGroupTypes ServiceCategoryGroup
        {
            get { return universalTariffListCtl1.ServiceCategoryGroup; }
            set
            {
                if (universalTariffListCtl1.ServiceCategoryGroup != value)
                {
                    universalTariffListCtl1.ServiceCategoryGroup = value;

                    OnTariffTypeChanged();
                }
            }
        }

        public UniversalTariffListCtl.DetailIDTypes DetailIDType
        {
            get { return universalTariffListCtl1.DetailIDType; }
            set
            {
                if (universalTariffListCtl1.DetailIDType != value)
                {
                    universalTariffListCtl1.DetailIDType = value;

                    if (universalTariffListCtl1.DetailIDType != UniversalTariffListCtl.DetailIDTypes.Untyped)
                    {
                        DetailID = null;
                    }
                    OnTariffTypeChanged();
                }
            }
        }

        private void OnTariffTypeChanged()
        {
            tabRecurringTariffPlans.PageVisible =
                UniversalTariffListCtl.CompareDetailIDTypes(DetailIDType,new[]{
                UniversalTariffListCtl.DetailIDTypes.Client,
                UniversalTariffListCtl.DetailIDTypes.Object,
                UniversalTariffListCtl.DetailIDTypes.ServiceGroup,
                UniversalTariffListCtl.DetailIDTypes.SuperTariff});

            tabPhoneTariffPlans.PageVisible =
                DetailIDType == UniversalTariffListCtl.DetailIDTypes.ServiceGroup
                && ServiceCategoryGroup == UniversalTariffListCtl.ServiceCategoryGroupTypes.Telephony
                || UniversalTariffListCtl.CompareDetailIDTypes(DetailIDType, new[]{
                UniversalTariffListCtl.DetailIDTypes.Client,
                UniversalTariffListCtl.DetailIDTypes.Object,
                UniversalTariffListCtl.DetailIDTypes.Operator,
                UniversalTariffListCtl.DetailIDTypes.SuperTariff});

            tabInetTariffPlans.PageVisible = 
                ServiceCategoryGroup == UniversalTariffListCtl.ServiceCategoryGroupTypes.Internet
                && ServiceCategoryGroup == UniversalTariffListCtl.ServiceCategoryGroupTypes.Internet
                || UniversalTariffListCtl.CompareDetailIDTypes(DetailIDType, new[]{
                UniversalTariffListCtl.DetailIDTypes.Client,
                UniversalTariffListCtl.DetailIDTypes.Object,
                UniversalTariffListCtl.DetailIDTypes.SuperTariff});
        }

        public Nullable<bool> Is_Basic
        {
            get { return universalTariffListCtl1.Is_Basic; }
            set
            {
                universalTariffListCtl1.Is_Basic = value;
            }
        }

        private void UniversalTariffEditorCtl_DetailIDChanged(object sender, EventArgs e)
        {
            universalTariffListCtl1.DetailID = DetailID;
        }

        public void RefreshControl()
        {
            universalTariffListCtl1.RefreshControl();
        }

        private void universalTariffListCtl1_ViewRowIDChanged(object sender, ShowDetailEventArgs e)
        {
            if (e != null)
            {
                phoneTariffEditorCtl1.DetailID = e.DetailID;
                recurringTariffEditorCtl1.DetailID = e.DetailID;
                inetTariffEditorCtl1.DetailID = e.DetailID;
            }
        }
    }
}
